define(['jquery', 'durandal/app', 'knockout', 'durandal/composition', 'slickGrid', 'WdatePicker',
        'pager', 'i18nCommon', 'http', 'selectize','bootbox', 'css!style/common/common-style'],
    function ($, app, ko, composition, Slick, WdatePicker, pager, i18nCommon, http, selectize,bootbox) {
        function modal() {

            var getReportList = http.getInstance("home/rec/getReportList", {type: "POST"});
            

            var self = this;

            self.reportQuery = ko.observable();
        
            self.textReportQuery = i18nCommon.textReportQuery

            self._gridOptions = {
                enableCellNavigation: true,
                enableColumnReorder: false,
                multiSelect: false
            };
            self._columns = [
                {id: 'reportId', name: '任务号', field: 'reportId', width: 90},
                {id: 'deviceId', name: '设备编号', field: 'deviceId', width: 110},
                {id: "createTime", "name": "上报时间", "field": "createTime", "width": 140},
                {id: "eventDesc", "name": "问题描述", "field": "eventDesc", "width": 240}
                
            ];

            composition.addBindingHandler('app-reportMgr-handler', {
                init: function (dom) {
                    self._dom = $(dom);
                    self.renderUI();
                    self.bindUI();
                }
            });

            self.bindUI = function () {
            	self._reportMgrGrid = new Slick.Grid($(".app-reportMgr-list"), {}, self._columns, self._gridOptions);
    			self._reportMgrGrid.setSelectionModel(new Slick.RowSelectionModel());
    			self._reportMgrGrid.onSelectedRowsChanged.subscribe(function (e,args) {				
    				var rows = args.rows;
    				if(rows === null || rows.length === 0){
    					selectedRow = null;
    					return;
    				}else{					
    					self.selectedRowData = self._reportMgrGrid.getData()[rows[0]];
    				}
    			});
    			self._reportMgrPager = pager.getInstance({
    				parent : $(".app-reportMgr-pager"),
    				changeHandler : function(pageInfo) {
    					self.getListData(self.deviceId,self._outGridPager._pageInfo.currentPage);
    				}
    			});
            };

            self.renderUI = function () { 
            	self.getListData("",1,10);
            };

            self.reportQuery = function(){
            	self.deviceId = $("#deviceId").val();
            	self.getListData(self.deviceId,1,10);
            }
            
            self.getListData = function (deviceId, currentPage,numPerPage) {
                var param = {};
                param.currentPage = currentPage || 1;
                param.numPerPage = numPerPage || 10;
                param.deviceId = deviceId;
 
                getReportList.ajax(param).then(function (data) {
                    self._reportMgrGrid.setData(data.list);
                    self._reportMgrGrid.setSelectedRows([]);
                    self._reportMgrGrid.render();
                    self._reportMgrPager.setPageInfo(data.pageInfo);
                }).error();
            };       
        }

        return modal;
    });